UCLA Stats 402

data = read.csv('~/Documents/MAS/402/Project 1/pokemon.csv')
names(data) = c('dex', 'name', 'type1', 'type2', 'total', 'hp', 'attack', 'defense', 'spattack',
                'spdefense', 'speed', 'generation', 'legendary')
data$generation = as.factor(data$generation)
types = names(table(data$type1))
data$bug = F
data$dark = F
data$dragon = F
data$electric = F
data$fairy = F
data$fighting = F
data$fire = F
data$flying = F
data$ghost = F
data$grass = F
data$ground = F
data$ice = F
data$normal = F
data$poison = F
data$psychic = F
data$rock = F
data$steel = F
data$water = F
for(j in 1:length(types)){
  for(i in 1:dim(data)[1]){
    if(data$type1[i] == types[j]){
      data[i, 13 + j] = T
    }
  }
}
for(j in 1:length(types)){
  for(i in 1:dim(data)[1]){
    if(data$type2[i] == types[j]){
      data[i, 13 + j] = T
    }
  }
}
set.seed(1)
t = sample(1:800, 800)
train = data[t[1:500],]
test = data[t[501:800],]
data = train
hist(data$hp, main = 'Histogram of HP', xlab = 'HP')

boxplot(data$hp, main = 'Boxplot of HP', ylab = 'HP')

qqnorm(data$hp, main = 'Normal Quantile Plot of HP', ylab = 'HP')

hist(data$attack, main = 'Histogram of Attack', xlab = 'Attack')

boxplot(data$attack, main = 'Boxplot of Attack', ylab = 'Attack')

hist(data$spattack, main = 'Histogram of Special Attack', xlab = 'Special Attack')

boxplot(data$spattack, main = 'Boxplot of Special Attack', ylab = 'Special Attack')

hist(data$defense, main = 'Histogram of Defense', xlab = 'Defense')

boxplot(data$defense, main = 'Boxplot of Defense', ylab = 'Defense')

hist(data$spdefense, main = 'Histogram of Special Defense', xlab = 'Special Defense')

boxplot(data$spdefense, main = 'Boxplot of Special Defense', ylab = 'Special Defense')

hist(data$speed, main = 'Histogram of Speed', xlab = 'Speed')

boxplot(data$speed, main = 'Boxplot of Speed', ylab = 'Speed')

table(data$generation)
## 
##   1   2   3   4   5   6 
## 111  71 104  70  97  47
boxplot(data$hp ~ data$generation, main = 'Boxplot of HP by Generation', ylab = 'HP')

table(data$legendary)
## 
## False  True 
##   460    40
boxplot(data$hp ~ data$legendary, main = 'Boxplot of HP by Legendary', ylab = 'HP')

table(data$type1) + table(data$type2)[2:19]
## 
##      Bug     Dark   Dragon Electric    Fairy Fighting     Fire   Flying 
##       44       39       33       30       24       36       35       67 
##    Ghost    Grass   Ground      Ice   Normal   Poison  Psychic     Rock 
##       24       58       42       29       56       43       52       41 
##    Steel    Water 
##       31       85
boxplot(data$hp ~ data$type1, main = 'Boxplot of HP by Type 1', ylab = 'HP')

addmargins(table(data$normal, data$flying))
##        
##         FALSE TRUE Sum
##   FALSE   389   55 444
##   TRUE     44   12  56
##   Sum     433   67 500
boxplot(data$hp ~ data$normal + data$flying, main = 'Boxplot of HP by Types Normal and Flying', xlab = 'Normal.Flying', ylab = 'HP')

addmargins(table(data$bug, data$flying))
##        
##         FALSE TRUE Sum
##   FALSE   399   57 456
##   TRUE     34   10  44
##   Sum     433   67 500
boxplot(data$hp ~ data$bug + data$flying, main = 'Boxplot of HP by Types Bug and Flying', xlab = 'Bug.Flying', ylab = 'HP')

library(car)
## Loading required package: carData
plot(data$attack, data$hp, main = 'HP by Attack', xlab = 'Attack', ylab = 'HP')
abline(lm(data$hp ~ data$attack))

outlierTest(lm(data$hp ~ data$attack))
##     rstudent unadjusted p-value Bonferonni p
## 444 7.192667         2.3517e-12   1.1759e-09
## 67  4.888954         1.3706e-06   6.8529e-04
plot(lm(data$hp ~ data$attack))

influencePlot(lm(data$hp ~ data$attack))

##        StudRes         Hat       CookD
## 67   4.8889544 0.002234555 0.025588096
## 100 -0.3557489 0.021877294 0.001417816
## 375  2.9977570 0.012686333 0.056824314
## 439  1.0703931 0.018134928 0.010577757
## 444  7.1926672 0.006131516 0.144829153
plot(data$spattack, data$hp, main = 'HP by Special Attack', xlab = 'Special Attack', ylab = 'HP')
abline(lm(data$hp ~ data$spattack))

outlierTest(lm(data$hp ~ data$spattack))
##     rstudent unadjusted p-value Bonferonni p
## 444 6.423274         3.1239e-10   1.5620e-07
## 67  4.532189         7.3211e-06   3.6606e-03
plot(lm(data$hp ~ data$spattack))

influencePlot(lm(data$hp ~ data$spattack))

##         StudRes         Hat        CookD
## 67   4.53218929 0.002515252 2.491989e-02
## 264 -0.04011011 0.024490516 2.023558e-05
## 286 -2.06207986 0.022419801 4.844326e-02
## 444  6.42327358 0.005352950 1.027178e-01
plot(data$defense, data$hp, main = 'HP by Defense', xlab = 'Defense', ylab = 'HP')
abline(lm(data$hp ~ data$defense))

outlierTest(lm(data$hp ~ data$defense))
##      rstudent unadjusted p-value Bonferonni p
## 444  5.703389         2.0183e-08   1.0091e-05
## 67   4.902329         1.2845e-06   6.4223e-04
## 245 -3.962736         8.4951e-05   4.2475e-02
plot(lm(data$hp ~ data$defense))

influencePlot(lm(data$hp ~ data$defense))

##         StudRes         Hat        CookD
## 67   4.90232942 0.003813691 4.396875e-02
## 245 -3.96273585 0.055969840 4.521595e-01
## 307  0.03981347 0.026969177 2.201115e-05
## 374 -1.97215110 0.026969177 5.358941e-02
## 444  5.70338883 0.002541495 3.897358e-02
plot(data$spdefense, data$hp, main = 'HP by Special Defense', xlab = 'Special Defense', ylab = 'HP')
abline(lm(data$hp ~ data$spdefense))

outlierTest(lm(data$hp ~ data$spdefense))
##      rstudent unadjusted p-value Bonferonni p
## 444  5.951822         5.0127e-09   2.5063e-06
## 67   5.175570         3.3037e-07   1.6519e-04
## 245 -4.868550         1.5127e-06   7.5637e-04
plot(lm(data$hp ~ data$spdefense))

influencePlot(lm(data$hp ~ data$spdefense))

##        StudRes         Hat        CookD
## 67   5.1755703 0.003821906 0.0488544869
## 245 -4.8685501 0.066075707 0.8019344895
## 264  0.1041085 0.021937885 0.0001217963
## 444  5.9518224 0.002479468 0.0411792181
plot(data$speed, data$hp, main = 'HP by Speed', xlab = 'Speed', ylab = 'HP')
abline(lm(data$hp ~ data$speed))

outlierTest(lm(data$hp ~ data$speed))
##     rstudent unadjusted p-value Bonferonni p
## 444 5.788202         1.2614e-08   6.3069e-06
## 67  4.573129         6.0734e-06   3.0367e-03
plot(lm(data$hp ~ data$speed))

influencePlot(lm(data$hp ~ data$speed))

##       StudRes         Hat      CookD
## 67   4.573129 0.002191251 0.02208076
## 134 -1.555796 0.019011157 0.02338745
## 286 -1.336433 0.019011157 0.01727921
## 333  3.536558 0.012401127 0.07675226
## 444  5.788202 0.005261120 0.08317019
summary(data$hp)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.00   50.00   65.00   68.21   80.00  190.00
summary(data$attack)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5.00   55.00   75.00   79.03  100.00  180.00
summary(data$spattack)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.00   50.00   70.00   73.95   95.00  180.00
summary(data$defense)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5.00   50.00   70.00   73.66   90.00  230.00
summary(data$spdefense)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   20.00   50.00   70.00   71.69   90.00  230.00
summary(data$speed)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5.00   47.50   66.00   68.63   90.00  150.00
tapply(data$hp, data$generation, mean, na.rm = T)
##        1        2        3        4        5        6 
## 63.50450 69.12676 65.99038 75.74286 71.00000 65.87234
tapply(data$hp, data$generation, sd, na.rm = T)
##        1        2        3        4        5        6 
## 23.12451 27.80027 24.68382 25.10482 20.86315 18.27640
tapply(data$hp, data$generation, var, na.rm = T)
##        1        2        3        4        5        6 
## 534.7432 772.8551 609.2912 630.2518 435.2708 334.0268
tapply(data$hp, data$legendary, mean, na.rm = T)
##    False     True 
## 65.88261 94.97500
tapply(data$hp, data$legendary, sd, na.rm = T)
##    False     True 
## 22.79776 19.36490
tapply(data$hp, data$legendary, var, na.rm = T)
##    False     True 
## 519.7378 374.9994
tapply(data$hp, data$type1, mean, na.rm = T)
##      Bug     Dark   Dragon Electric    Fairy Fighting     Fire   Flying 
## 58.83721 69.04000 81.70000 61.24000 71.77778 62.09524 70.96429 62.50000 
##    Ghost    Grass   Ground      Ice   Normal   Poison  Psychic     Rock 
## 56.75000 65.54545 72.59091 72.73684 73.85185 67.60000 69.39394 62.39286 
##    Steel    Water 
## 60.81250 73.34667
tapply(data$hp, data$type1, sd, na.rm = T)
##      Bug     Dark   Dragon Electric    Fairy Fighting     Fire   Flying 
## 15.38077 22.15378 23.06079 19.71311 23.16127 19.20392 21.08797 31.81981 
##    Ghost    Grass   Ground      Ice   Normal   Poison  Psychic     Rock 
## 29.58265 20.20414 26.76647 21.69189 24.75800 20.09032 33.09073 20.04317 
##    Steel    Water 
## 14.37228 27.64079
tapply(data$hp, data$type1, var, na.rm = T)
##       Bug      Dark    Dragon  Electric     Fairy  Fighting      Fire 
##  236.5681  490.7900  531.8000  388.6067  536.4444  368.7905  444.7024 
##    Flying     Ghost     Grass    Ground       Ice    Normal    Poison 
## 1012.5000  875.1333  408.2072  716.4437  470.5380  612.9588  403.6211 
##   Psychic      Rock     Steel     Water 
## 1094.9962  401.7288  206.5625  764.0133
sort(tapply(data$hp, data$type1, mean, na.rm = T) - mean(data$hp))
##      Ghost        Bug      Steel   Electric   Fighting       Rock 
## -11.460000  -9.372791  -7.397500  -6.970000  -6.114762  -5.817143 
##     Flying      Grass     Poison       Dark    Psychic       Fire 
##  -5.710000  -2.664545  -0.610000   0.830000   1.183939   2.754286 
##      Fairy     Ground        Ice      Water     Normal     Dragon 
##   3.567778   4.380909   4.526842   5.136667   5.641852  13.490000
mfull = lm(hp ~ attack + defense + spattack + spdefense + speed + generation + legendary + bug + dark + dragon + electric + fairy + fighting + fire + flying + ghost + grass + ground + ice + normal + poison + psychic + rock + steel + water + normal*flying + bug*flying, data = data)
summary(mfull)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + speed + 
##     generation + legendary + bug + dark + dragon + electric + 
##     fairy + fighting + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + psychic + rock + steel + water + 
##     normal * flying + bug * flying, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -47.541 -10.379  -2.351   8.687 139.632 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            18.03419    4.48587   4.020 6.78e-05 ***
## attack                  0.30397    0.03653   8.321 9.64e-16 ***
## defense                 0.04940    0.04130   1.196 0.232214    
## spattack                0.15012    0.04015   3.739 0.000208 ***
## spdefense               0.15937    0.04136   3.853 0.000133 ***
## speed                  -0.08563    0.03788  -2.260 0.024251 *  
## generation2             8.16726    2.97255   2.748 0.006236 ** 
## generation3             3.03058    2.65643   1.141 0.254518    
## generation4             9.33817    2.95671   3.158 0.001690 ** 
## generation5             7.65517    2.68488   2.851 0.004548 ** 
## generation6             6.54225    3.40146   1.923 0.055040 .  
## legendaryTrue           2.76070    3.59658   0.768 0.443117    
## bugTRUE                -2.86478    3.76056  -0.762 0.446565    
## darkTRUE               -5.73582    3.48824  -1.644 0.100780    
## dragonTRUE             -0.20348    3.85993  -0.053 0.957982    
## electricTRUE           -2.78959    4.21222  -0.662 0.508129    
## fairyTRUE              -0.69349    4.28797  -0.162 0.871588    
## fightingTRUE           -1.30853    3.77116  -0.347 0.728760    
## fireTRUE               -4.94841    3.94232  -1.255 0.210031    
## flyingTRUE              6.04851    3.17711   1.904 0.057553 .  
## ghostTRUE             -10.16479    4.31876  -2.354 0.019003 *  
## grassTRUE              -2.84799    3.18078  -0.895 0.371047    
## groundTRUE              5.94677    3.34074   1.780 0.075713 .  
## iceTRUE                 5.44384    3.94553   1.380 0.168322    
## normalTRUE             11.51018    3.77191   3.052 0.002406 ** 
## poisonTRUE              4.32315    3.50769   1.232 0.218389    
## psychicTRUE            -0.10211    3.63534  -0.028 0.977604    
## rockTRUE               -7.92604    3.55214  -2.231 0.026131 *  
## steelTRUE             -12.45512    4.01574  -3.102 0.002041 ** 
## waterTRUE               6.04489    2.94185   2.055 0.040454 *  
## flyingTRUE:normalTRUE  -8.38795    6.69048  -1.254 0.210572    
## bugTRUE:flyingTRUE     -3.17184    7.41655  -0.428 0.669088    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.2 on 468 degrees of freedom
## Multiple R-squared:  0.455,  Adjusted R-squared:  0.4189 
## F-statistic:  12.6 on 31 and 468 DF,  p-value: < 2.2e-16
outlierTest(mfull)
##     rstudent unadjusted p-value Bonferonni p
## 218 8.415041         4.8362e-16   2.4181e-13
## 352 5.626309         3.1774e-08   1.5887e-05
## 545 3.994650         7.5255e-05   3.7627e-02
plot(mfull)

influencePlot(mfull)

##       StudRes        Hat       CookD
## 352  5.626309 0.02845789 0.027194658
## 231 -2.968200 0.21234868 0.073006903
## 138 -1.259418 0.14319834 0.008273783
## 218  8.415041 0.04449261 0.089666656
data[which(t == 231),]
##     dex    name type1 type2 total hp attack defense spattack spdefense
## 231 213 Shuckle   Bug  Rock   505 20     10     230       10       230
##     speed generation legendary  bug  dark dragon electric fairy fighting
## 231     5          2     False TRUE FALSE  FALSE    FALSE FALSE    FALSE
##      fire flying ghost grass ground   ice normal poison psychic rock steel
## 231 FALSE  FALSE FALSE FALSE  FALSE FALSE  FALSE  FALSE   FALSE TRUE FALSE
##     water
## 231 FALSE
mfull2 = lm(hp ~ attack + defense + spattack + spdefense + speed + generation + legendary + bug + dark + dragon + electric + fairy + fighting + fire + flying + ghost + grass + ground + ice + normal + poison + psychic + rock + steel + water + normal*flying + bug*flying, data = data[-which(t == 231),])
summary(mfull2)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + speed + 
##     generation + legendary + bug + dark + dragon + electric + 
##     fairy + fighting + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + psychic + rock + steel + water + 
##     normal * flying + bug * flying, data = data[-which(t == 231), 
##     ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -44.218 -10.322  -2.081   8.288 138.814 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            17.07571    4.46060   3.828 0.000147 ***
## attack                  0.28576    0.03675   7.777 4.81e-14 ***
## defense                 0.06896    0.04148   1.662 0.097116 .  
## spattack                0.13972    0.03997   3.495 0.000519 ***
## spdefense               0.18971    0.04227   4.487 9.09e-06 ***
## speed                  -0.08951    0.03759  -2.381 0.017665 *  
## generation2             8.71213    2.95376   2.950 0.003343 ** 
## generation3             3.24680    2.63555   1.232 0.218597    
## generation4             9.25717    2.93247   3.157 0.001698 ** 
## generation5             7.74150    2.66291   2.907 0.003821 ** 
## generation6             6.49197    3.37347   1.924 0.054909 .  
## legendaryTrue           2.53639    3.56774   0.711 0.477486    
## bugTRUE                -1.36726    3.76353  -0.363 0.716551    
## darkTRUE               -5.47848    3.46058  -1.583 0.114073    
## dragonTRUE             -0.20747    3.82812  -0.054 0.956801    
## electricTRUE           -2.95818    4.17789  -0.708 0.479264    
## fairyTRUE              -1.39549    4.25920  -0.328 0.743329    
## fightingTRUE           -1.11493    3.74065  -0.298 0.765792    
## fireTRUE               -4.97363    3.90984  -1.272 0.203978    
## flyingTRUE              5.96651    3.15105   1.893 0.058909 .  
## ghostTRUE             -10.39395    4.28386  -2.426 0.015631 *  
## grassTRUE              -3.14884    3.15619  -0.998 0.318955    
## groundTRUE              5.79020    3.31363   1.747 0.081227 .  
## iceTRUE                 5.28003    3.91340   1.349 0.177920    
## normalTRUE             11.45817    3.74087   3.063 0.002318 ** 
## poisonTRUE              3.97272    3.48078   1.141 0.254318    
## psychicTRUE            -0.69124    3.61084  -0.191 0.848268    
## rockTRUE               -7.36291    3.52797  -2.087 0.037429 *  
## steelTRUE             -13.80663    4.00859  -3.444 0.000624 ***
## waterTRUE               5.73735    2.91944   1.965 0.049981 *  
## flyingTRUE:normalTRUE  -7.84262    6.63788  -1.181 0.238008    
## bugTRUE:flyingTRUE     -4.82948    7.37660  -0.655 0.512981    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.05 on 467 degrees of freedom
## Multiple R-squared:  0.4606, Adjusted R-squared:  0.4248 
## F-statistic: 12.87 on 31 and 467 DF,  p-value: < 2.2e-16
outlierTest(mfull2)
##     rstudent unadjusted p-value Bonferonni p
## 218 8.440826         4.0144e-16   2.0032e-13
## 352 5.779844         1.3702e-08   6.8375e-06
## 351 4.023857         6.6798e-05   3.3332e-02
## 545 3.951437         8.9721e-05   4.4771e-02
plot(mfull2)

influencePlot(mfull2)
##        StudRes        Hat       CookD
## 751 -0.6441763 0.14572503 0.002214830
## 352  5.7798435 0.02936398 0.029532708
## 545  3.9514371 0.11128913 0.059247540
## 138 -1.2681354 0.14319864 0.008388317
## 218  8.4408261 0.04472630 0.090614459
library(effects)
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.

data$normal = as.factor(data$normal)
data$bug = as.factor(data$bug)
data$flying = as.factor(data$flying)
plot(allEffects(lm(hp ~ normal*flying + bug*flying, data = data), ask = F))

library(MASS)
maic = stepAIC(mfull2)
## Start:  AIC=2918.14
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + dragon + electric + fairy + fighting + 
##     fire + flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + normal * flying + bug * 
##     flying
## 
##                 Df Sum of Sq    RSS    AIC
## - dragon         1       1.0 152105 2916.1
## - psychic        1      11.9 152116 2916.2
## - fighting       1      28.9 152133 2916.2
## - fairy          1      35.0 152139 2916.2
## - bug:flying     1     139.6 152244 2916.6
## - electric       1     163.3 152267 2916.7
## - legendary      1     164.6 152269 2916.7
## - grass          1     324.2 152428 2917.2
## - poison         1     424.3 152528 2917.5
## - flying:normal  1     454.7 152559 2917.6
## - fire           1     527.1 152631 2917.9
## - ice            1     592.9 152697 2918.1
## <none>                       152104 2918.1
## - dark           1     816.3 152920 2918.8
## - defense        1     900.0 153004 2919.1
## - ground         1     994.5 153098 2919.4
## - water          1    1257.9 153362 2920.2
## - rock           1    1418.6 153523 2920.8
## - speed          1    1846.5 153950 2922.2
## - ghost          1    1917.4 154021 2922.4
## - generation     5    5308.2 157412 2925.2
## - steel          1    3863.8 155968 2928.7
## - spattack       1    3979.1 156083 2929.0
## - spdefense      1    6558.8 158663 2937.2
## - attack         1   19697.1 171801 2976.9
## 
## Step:  AIC=2916.14
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fairy + fighting + fire + 
##     flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - psychic        1      11.0 152116 2914.2
## - fighting       1      28.2 152133 2914.2
## - fairy          1      34.0 152139 2914.2
## - bug:flying     1     138.7 152244 2914.6
## - legendary      1     163.9 152269 2914.7
## - electric       1     166.7 152272 2914.7
## - grass          1     348.8 152454 2915.3
## - poison         1     452.0 152557 2915.6
## - flying:normal  1     455.7 152561 2915.6
## - fire           1     559.2 152664 2916.0
## <none>                       152105 2916.1
## - ice            1     632.4 152737 2916.2
## - dark           1     850.2 152955 2916.9
## - defense        1     899.3 153004 2917.1
## - ground         1    1028.7 153134 2917.5
## - water          1    1444.0 153549 2918.9
## - rock           1    1469.5 153575 2918.9
## - speed          1    1847.2 153952 2920.2
## - ghost          1    1978.3 154083 2920.6
## - generation     5    5310.0 157415 2923.3
## - steel          1    3987.0 156092 2927.1
## - spattack       1    4013.5 156118 2927.1
## - spdefense      1    6562.2 158667 2935.2
## - attack         1   19756.5 171861 2975.1
## 
## Step:  AIC=2914.18
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fairy + fighting + fire + 
##     flying + ghost + grass + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fighting       1      24.1 152140 2912.3
## - fairy          1      27.8 152144 2912.3
## - bug:flying     1     134.8 152251 2912.6
## - electric       1     158.4 152274 2912.7
## - legendary      1     163.4 152279 2912.7
## - grass          1     350.2 152466 2913.3
## - flying:normal  1     461.8 152578 2913.7
## - poison         1     527.9 152644 2913.9
## - fire           1     573.3 152689 2914.1
## <none>                       152116 2914.2
## - ice            1     720.4 152836 2914.5
## - dark           1     843.7 152960 2914.9
## - defense        1     895.9 153012 2915.1
## - ground         1    1081.8 153198 2915.7
## - rock           1    1465.8 153582 2917.0
## - water          1    1827.8 153944 2918.1
## - speed          1    1871.5 153987 2918.3
## - ghost          1    2015.5 154131 2918.7
## - generation     5    5345.2 157461 2921.4
## - steel          1    3985.8 156102 2925.1
## - spattack       1    4201.2 156317 2925.8
## - spdefense      1    6585.5 158701 2933.3
## - attack         1   22128.1 174244 2979.9
## 
## Step:  AIC=2912.26
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fairy + fire + flying + 
##     ghost + grass + ground + ice + normal + poison + rock + steel + 
##     water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fairy          1      21.9 152162 2910.3
## - bug:flying     1     142.3 152282 2910.7
## - electric       1     143.7 152284 2910.7
## - legendary      1     172.3 152312 2910.8
## - grass          1     330.9 152471 2911.3
## - flying:normal  1     476.6 152617 2911.8
## - fire           1     560.4 152700 2912.1
## - poison         1     563.0 152703 2912.1
## <none>                       152140 2912.3
## - ice            1     797.1 152937 2912.9
## - dark           1     819.8 152960 2912.9
## - defense        1     910.5 153051 2913.2
## - ground         1    1224.6 153365 2914.3
## - rock           1    1442.4 153582 2915.0
## - speed          1    1894.9 154035 2916.4
## - water          1    1985.0 154125 2916.7
## - ghost          1    1992.3 154132 2916.8
## - generation     5    5323.6 157464 2919.4
## - steel          1    3965.3 156105 2923.1
## - spattack       1    4495.3 156635 2924.8
## - spdefense      1    6562.6 158703 2931.3
## - attack         1   23036.7 175177 2980.6
## 
## Step:  AIC=2910.33
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fire + flying + ghost + 
##     grass + ground + ice + normal + poison + rock + steel + water + 
##     flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - electric       1     130.3 152292 2908.8
## - bug:flying     1     140.7 152303 2908.8
## - legendary      1     175.9 152338 2908.9
## - grass          1     315.0 152477 2909.4
## - flying:normal  1     478.6 152641 2909.9
## - fire           1     539.9 152702 2910.1
## - poison         1     597.3 152759 2910.3
## <none>                       152162 2910.3
## - dark           1     801.4 152963 2910.9
## - ice            1     840.9 153003 2911.1
## - defense        1     914.9 153077 2911.3
## - ground         1    1266.6 153429 2912.5
## - rock           1    1422.8 153585 2913.0
## - speed          1    1874.5 154036 2914.4
## - ghost          1    1972.3 154134 2914.8
## - water          1    2105.4 154267 2915.2
## - generation     5    5312.4 157474 2917.4
## - steel          1    3970.4 156132 2921.2
## - spattack       1    4475.6 156637 2922.8
## - spdefense      1    6550.6 158713 2929.4
## - attack         1   23547.5 175709 2980.1
## 
## Step:  AIC=2908.75
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + fire + flying + ghost + grass + 
##     ground + ice + normal + poison + rock + steel + water + flying:normal + 
##     bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - bug:flying     1     124.9 152417 2907.2
## - legendary      1     183.2 152475 2907.3
## - grass          1     266.2 152558 2907.6
## - fire           1     469.3 152762 2908.3
## - flying:normal  1     478.2 152770 2908.3
## <none>                       152292 2908.8
## - poison         1     692.6 152985 2909.0
## - dark           1     737.3 153030 2909.2
## - defense        1     910.3 153203 2909.7
## - ice            1     946.5 153239 2909.8
## - ground         1    1316.4 153609 2911.1
## - rock           1    1362.9 153655 2911.2
## - ghost          1    1895.0 154187 2912.9
## - speed          1    1930.3 154223 2913.0
## - water          1    2403.3 154696 2914.6
## - generation     5    5242.9 157535 2915.6
## - steel          1    3961.7 156254 2919.6
## - spattack       1    4345.7 156638 2920.8
## - spdefense      1    6674.5 158967 2928.2
## - attack         1   24220.6 176513 2980.4
## 
## Step:  AIC=2907.16
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + fire + flying + ghost + grass + 
##     ground + ice + normal + poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - bug            1     114.7 152532 2905.5
## - legendary      1     223.1 152640 2905.9
## - grass          1     251.9 152669 2906.0
## - flying:normal  1     409.1 152826 2906.5
## - fire           1     446.5 152864 2906.6
## <none>                       152417 2907.2
## - dark           1     731.8 153149 2907.6
## - poison         1     766.2 153183 2907.7
## - defense        1     919.2 153336 2908.2
## - ice            1     954.0 153371 2908.3
## - ground         1    1312.3 153729 2909.4
## - rock           1    1345.2 153762 2909.6
## - speed          1    1876.1 154293 2911.3
## - ghost          1    1909.2 154326 2911.4
## - water          1    2414.3 154831 2913.0
## - generation     5    5206.4 157624 2913.9
## - steel          1    3876.8 156294 2917.7
## - spattack       1    4232.3 156649 2918.8
## - spdefense      1    6652.4 159070 2926.5
## - attack         1   24235.4 176653 2978.8
## 
## Step:  AIC=2905.54
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + dark + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - grass          1     221.9 152754 2904.3
## - legendary      1     240.7 152773 2904.3
## - flying:normal  1     391.0 152923 2904.8
## - fire           1     406.4 152938 2904.9
## <none>                       152532 2905.5
## - dark           1     672.2 153204 2905.7
## - poison         1     725.8 153258 2905.9
## - defense        1     891.1 153423 2906.4
## - ice            1    1029.5 153561 2906.9
## - rock           1    1296.7 153829 2907.8
## - ground         1    1431.1 153963 2908.2
## - ghost          1    1832.9 154365 2909.5
## - speed          1    1887.1 154419 2909.7
## - generation     5    5136.8 157669 2912.1
## - water          1    2701.4 155233 2912.3
## - steel          1    3888.0 156420 2916.1
## - spattack       1    4418.3 156950 2917.8
## - spdefense      1    6805.6 159337 2925.3
## - attack         1   24180.4 176712 2977.0
## 
## Step:  AIC=2904.26
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + dark + fire + flying + ghost + ground + ice + 
##     normal + poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - legendary      1     257.9 153012 2903.1
## - fire           1     330.6 153084 2903.3
## - flying:normal  1     407.6 153161 2903.6
## - dark           1     605.0 153359 2904.2
## <none>                       152754 2904.3
## - poison         1     711.6 153465 2904.6
## - defense        1     861.4 153615 2905.1
## - ice            1    1122.5 153876 2905.9
## - rock           1    1196.7 153950 2906.2
## - ground         1    1603.6 154357 2907.5
## - ghost          1    1763.9 154518 2908.0
## - speed          1    1771.5 154525 2908.0
## - generation     5    5031.1 157785 2910.4
## - water          1    3099.0 155853 2912.3
## - steel          1    3685.6 156439 2914.2
## - spattack       1    4314.6 157068 2916.2
## - spdefense      1    6842.5 159596 2924.1
## - attack         1   24252.2 177006 2975.8
## 
## Step:  AIC=2903.11
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     dark + fire + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - fire           1     338.5 153350 2902.2
## - flying:normal  1     446.3 153458 2902.6
## <none>                       153012 2903.1
## - dark           1     671.8 153683 2903.3
## - poison         1     684.8 153696 2903.3
## - defense        1     924.9 153936 2904.1
## - ice            1    1095.1 154107 2904.7
## - rock           1    1227.8 154239 2905.1
## - ground         1    1652.9 154665 2906.5
## - speed          1    1692.6 154704 2906.6
## - ghost          1    1783.1 154795 2906.9
## - generation     5    5275.1 158287 2910.0
## - water          1    2996.0 156008 2910.8
## - steel          1    3890.2 156902 2913.6
## - spattack       1    4958.4 157970 2917.0
## - spdefense      1    7206.7 160218 2924.1
## - attack         1   25589.4 178601 2978.3
## 
## Step:  AIC=2902.21
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     dark + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - flying:normal  1     448.4 153798 2901.7
## <none>                       153350 2902.2
## - dark           1     642.1 153992 2902.3
## - poison         1     800.4 154150 2902.8
## - defense        1     916.7 154267 2903.2
## - rock           1    1185.6 154536 2904.1
## - ice            1    1248.2 154598 2904.2
## - ground         1    1682.2 155032 2905.7
## - speed          1    1706.1 155056 2905.7
## - ghost          1    1756.0 155106 2905.9
## - generation     5    5142.5 158493 2908.7
## - water          1    3378.8 156729 2911.1
## - steel          1    3746.3 157096 2912.2
## - spattack       1    4638.0 157988 2915.1
## - spdefense      1    7489.9 160840 2924.0
## - attack         1   25566.6 178917 2977.2
## 
## Step:  AIC=2901.67
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     dark + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water
## 
##              Df Sum of Sq    RSS    AIC
## <none>                    153798 2901.7
## - dark        1     669.4 154468 2901.8
## - poison      1     785.7 154584 2902.2
## - defense     1     915.2 154714 2902.6
## - flying      1    1197.9 154996 2903.5
## - ice         1    1199.8 154998 2903.5
## - rock        1    1209.9 155008 2903.6
## - ground      1    1656.5 155455 2905.0
## - speed       1    1666.3 155465 2905.0
## - ghost       1    1801.8 155600 2905.5
## - generation  5    5387.2 159186 2908.8
## - water       1    3307.3 157106 2910.3
## - steel       1    3881.2 157680 2912.1
## - spattack    1    4544.1 158343 2914.2
## - normal      1    5657.6 159456 2917.7
## - spdefense   1    7753.7 161552 2924.2
## - attack      1   25630.8 179429 2976.6
summary(maic)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + speed + 
##     generation + dark + flying + ghost + ground + ice + normal + 
##     poison + rock + steel + water, data = data[-which(t == 231), 
##     ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -42.650 -10.614  -2.575   8.437 140.565 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  13.97162    3.75668   3.719 0.000224 ***
## attack        0.29368    0.03291   8.925  < 2e-16 ***
## defense       0.06911    0.04098   1.687 0.092350 .  
## spattack      0.13027    0.03467   3.758 0.000192 ***
## spdefense     0.20067    0.04088   4.909 1.26e-06 ***
## speed        -0.08354    0.03671  -2.276 0.023306 *  
## generation2   8.58241    2.89323   2.966 0.003164 ** 
## generation3   3.37154    2.57415   1.310 0.190902    
## generation4   9.24855    2.86732   3.226 0.001344 ** 
## generation5   7.80147    2.61605   2.982 0.003008 ** 
## generation6   6.37553    3.28490   1.941 0.052863 .  
## darkTRUE     -4.52930    3.14007  -1.442 0.149839    
## flyingTRUE    4.78515    2.48000   1.929 0.054261 .  
## ghostTRUE    -9.33299    3.94397  -2.366 0.018360 *  
## groundTRUE    6.94635    3.06142   2.269 0.023713 *  
## iceTRUE       6.76176    3.50160   1.931 0.054068 .  
## normalTRUE   11.65337    2.77907   4.193 3.28e-05 ***
## poisonTRUE    4.90115    3.13649   1.563 0.118803    
## rockTRUE     -6.38275    3.29147  -1.939 0.053068 .  
## steelTRUE   -13.09680    3.77089  -3.473 0.000561 ***
## waterTRUE     7.29443    2.27519   3.206 0.001436 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.94 on 478 degrees of freedom
## Multiple R-squared:  0.4546, Adjusted R-squared:  0.4318 
## F-statistic: 19.92 on 20 and 478 DF,  p-value: < 2.2e-16
outlierTest(maic)
##     rstudent unadjusted p-value Bonferonni p
## 218 8.497498         2.4930e-16   1.2440e-13
## 352 5.847534         9.2669e-09   4.6242e-06
## 351 4.089665         5.0703e-05   2.5301e-02
## 545 4.035555         6.3439e-05   3.1656e-02
plot(maic)

influencePlot(maic)

##        StudRes        Hat       CookD
## 751 -0.5999364 0.13983316 0.002789976
## 352  5.8475342 0.02641985 0.041316865
## 545  4.0355547 0.06609091 0.053180657
## 99  -1.9434648 0.11917870 0.024195192
## 218  8.4974983 0.02285907 0.070009304
vif(maic)
##                GVIF Df GVIF^(1/(2*Df))
## attack     1.709810  1        1.307597
## defense    2.235812  1        1.495263
## spattack   1.852368  1        1.361017
## spdefense  1.900783  1        1.378689
## speed      1.613357  1        1.270180
## generation 1.369209  5        1.031922
## dark       1.101732  1        1.049634
## flying     1.108758  1        1.052976
## ghost      1.104451  1        1.050929
## ground     1.120436  1        1.058506
## ice        1.040890  1        1.020240
## normal     1.193344  1        1.092403
## poison     1.201426  1        1.096096
## rock       1.238878  1        1.113049
## steel      1.284905  1        1.133537
## water      1.134571  1        1.065162
mbic = stepAIC(mfull2, k = log(length(mfull2$residuals)))
## Start:  AIC=3052.94
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + dragon + electric + fairy + fighting + 
##     fire + flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + normal * flying + bug * 
##     flying
## 
##                 Df Sum of Sq    RSS    AIC
## - generation     5    5308.2 157412 3039.0
## - dragon         1       1.0 152105 3046.7
## - psychic        1      11.9 152116 3046.8
## - fighting       1      28.9 152133 3046.8
## - fairy          1      35.0 152139 3046.8
## - bug:flying     1     139.6 152244 3047.2
## - electric       1     163.3 152267 3047.3
## - legendary      1     164.6 152269 3047.3
## - grass          1     324.2 152428 3047.8
## - poison         1     424.3 152528 3048.1
## - flying:normal  1     454.7 152559 3048.2
## - fire           1     527.1 152631 3048.4
## - ice            1     592.9 152697 3048.7
## - dark           1     816.3 152920 3049.4
## - defense        1     900.0 153004 3049.7
## - ground         1     994.5 153098 3050.0
## - water          1    1257.9 153362 3050.8
## - rock           1    1418.6 153523 3051.4
## - speed          1    1846.5 153950 3052.8
## <none>                       152104 3052.9
## - ghost          1    1917.4 154021 3053.0
## - steel          1    3863.8 155968 3059.2
## - spattack       1    3979.1 156083 3059.6
## - spdefense      1    6558.8 158663 3067.8
## - attack         1   19697.1 171801 3107.5
## 
## Step:  AIC=3038.99
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + dragon + electric + fairy + fighting + fire + 
##     flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - dragon         1       2.8 157415 3032.8
## - fighting       1       4.0 157416 3032.8
## - fairy          1      19.1 157431 3032.8
## - psychic        1      36.2 157448 3032.9
## - poison         1      53.6 157466 3032.9
## - electric       1      92.3 157504 3033.1
## - bug:flying     1     101.4 157514 3033.1
## - grass          1     180.6 157593 3033.3
## - fire           1     322.8 157735 3033.8
## - dark           1     400.2 157812 3034.1
## - legendary      1     404.8 157817 3034.1
## - flying:normal  1     669.8 158082 3034.9
## - defense        1     679.1 158091 3034.9
## - ice            1     939.9 158352 3035.8
## - water          1     993.4 158406 3035.9
## - ground         1    1069.9 158482 3036.2
## - rock           1    1312.3 158725 3036.9
## - ghost          1    1927.9 159340 3038.9
## <none>                       157412 3039.0
## - speed          1    2290.4 159703 3040.0
## - steel          1    3076.3 160489 3042.4
## - spattack       1    3824.2 161236 3044.8
## - spdefense      1    7647.5 165060 3056.4
## - attack         1   19283.7 176696 3090.4
## 
## Step:  AIC=3032.79
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + electric + fairy + fighting + fire + flying + 
##     ghost + grass + ground + ice + normal + poison + psychic + 
##     rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fighting       1       6.4 157421 3026.6
## - fairy          1      22.2 157437 3026.7
## - psychic        1      46.2 157461 3026.7
## - poison         1      50.9 157466 3026.7
## - bug:flying     1     103.6 157519 3026.9
## - electric       1     106.2 157521 3026.9
## - grass          1     214.7 157630 3027.3
## - fire           1     370.1 157785 3027.8
## - legendary      1     408.5 157823 3027.9
## - dark           1     437.4 157852 3028.0
## - flying:normal  1     668.5 158083 3028.7
## - defense        1     683.7 158099 3028.7
## - ice            1     962.0 158377 3029.6
## - ground         1    1078.5 158494 3030.0
## - water          1    1081.1 158496 3030.0
## - rock           1    1397.8 158813 3031.0
## <none>                       157415 3032.8
## - ghost          1    2018.9 159434 3032.9
## - speed          1    2290.0 159705 3033.8
## - steel          1    3217.8 160633 3036.7
## - spattack       1    3891.2 161306 3038.8
## - spdefense      1    7665.6 165081 3050.3
## - attack         1   19407.1 176822 3084.6
## 
## Step:  AIC=3026.6
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + electric + fairy + fire + flying + ghost + grass + 
##     ground + ice + normal + poison + psychic + rock + steel + 
##     water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fairy          1      19.0 157440 3020.4
## - psychic        1      42.3 157464 3020.5
## - poison         1      58.3 157480 3020.6
## - electric       1     100.2 157522 3020.7
## - bug:flying     1     106.3 157528 3020.7
## - grass          1     208.4 157630 3021.1
## - fire           1     363.8 157785 3021.5
## - legendary      1     416.3 157838 3021.7
## - dark           1     434.1 157856 3021.8
## - flying:normal  1     680.4 158102 3022.5
## - defense        1     690.0 158111 3022.6
## - ice            1    1041.1 158462 3023.7
## - water          1    1188.6 158610 3024.1
## - ground         1    1195.6 158617 3024.2
## - rock           1    1405.9 158827 3024.8
## <none>                       157421 3026.6
## - ghost          1    2036.4 159458 3026.8
## - speed          1    2312.5 159734 3027.7
## - steel          1    3231.7 160653 3030.5
## - spattack       1    4026.3 161448 3033.0
## - spdefense      1    7665.6 165087 3044.1
## - attack         1   19940.8 177362 3079.9
## 
## Step:  AIC=3020.45
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + electric + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + psychic + rock + steel + water + 
##     flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - psychic        1      34.0 157474 3014.3
## - poison         1      73.0 157513 3014.5
## - electric       1      86.8 157527 3014.5
## - bug:flying     1     104.2 157545 3014.6
## - grass          1     192.9 157633 3014.8
## - fire           1     345.5 157786 3015.3
## - dark           1     418.6 157859 3015.6
## - legendary      1     420.4 157861 3015.6
## - flying:normal  1     682.7 158123 3016.4
## - defense        1     694.0 158134 3016.4
## - ice            1    1112.4 158553 3017.8
## - ground         1    1246.4 158687 3018.2
## - water          1    1311.6 158752 3018.4
## - rock           1    1387.2 158827 3018.6
## <none>                       157440 3020.4
## - ghost          1    2025.2 159466 3020.6
## - speed          1    2293.9 159734 3021.4
## - steel          1    3230.3 160671 3024.4
## - spattack       1    4009.4 161450 3026.8
## - spdefense      1    7686.1 165126 3038.0
## - attack         1   20815.5 178256 3076.2
## 
## Step:  AIC=3014.34
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + electric + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + rock + steel + water + flying:normal + 
##     bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - electric       1      60.8 157535 3008.3
## - bug:flying     1      97.5 157572 3008.4
## - poison         1     105.4 157580 3008.5
## - grass          1     161.2 157636 3008.6
## - fire           1     311.5 157786 3009.1
## - dark           1     392.9 157867 3009.4
## - legendary      1     416.7 157891 3009.4
## - defense        1     687.0 158161 3010.3
## - flying:normal  1     691.9 158166 3010.3
## - ice            1    1254.7 158729 3012.1
## - ground         1    1296.8 158771 3012.2
## - rock           1    1354.9 158829 3012.4
## - water          1    1662.6 159137 3013.4
## <none>                       157474 3014.3
## - ghost          1    1997.5 159472 3014.4
## - speed          1    2338.2 159813 3015.5
## - steel          1    3196.9 160671 3018.2
## - spattack       1    4134.6 161609 3021.1
## - spdefense      1    7654.8 165129 3031.8
## - attack         1   23773.0 181247 3078.3
## 
## Step:  AIC=3008.32
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + fire + flying + ghost + grass + ground + ice + 
##     normal + poison + rock + steel + water + flying:normal + 
##     bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - bug:flying     1      88.4 157624 3002.4
## - poison         1     131.7 157667 3002.5
## - grass          1     136.7 157672 3002.5
## - fire           1     276.6 157812 3003.0
## - dark           1     362.6 157898 3003.3
## - legendary      1     424.2 157959 3003.4
## - defense        1     684.1 158219 3004.3
## - flying:normal  1     690.2 158225 3004.3
## - rock           1    1317.2 158852 3006.3
## - ground         1    1333.0 158868 3006.3
## - ice            1    1345.7 158881 3006.3
## - water          1    1860.9 159396 3008.0
## - ghost          1    1945.1 159480 3008.2
## <none>                       157535 3008.3
## - speed          1    2383.1 159918 3009.6
## - steel          1    3191.3 160726 3012.1
## - spattack       1    4087.4 161623 3014.9
## - spdefense      1    7741.9 165277 3026.1
## - attack         1   24352.3 181887 3073.8
## 
## Step:  AIC=3002.39
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     bug + dark + fire + flying + ghost + grass + ground + ice + 
##     normal + poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - bug            1      45.1 157669 2996.3
## - grass          1     129.2 157753 2996.6
## - poison         1     160.7 157784 2996.7
## - fire           1     262.5 157886 2997.0
## - dark           1     359.7 157983 2997.3
## - legendary      1     473.8 158097 2997.7
## - flying:normal  1     624.4 158248 2998.2
## - defense        1     692.2 158316 2998.4
## - rock           1    1302.8 158926 3000.3
## - ground         1    1325.2 158949 3000.3
## - ice            1    1350.8 158974 3000.4
## - water          1    1867.9 159491 3002.1
## - ghost          1    1961.8 159585 3002.3
## <none>                       157624 3002.4
## - speed          1    2330.0 159954 3003.5
## - steel          1    3136.6 160760 3006.0
## - spattack       1    4001.0 161625 3008.7
## - spdefense      1    7707.3 165331 3020.0
## - attack         1   24391.6 182015 3068.0
## 
## Step:  AIC=2996.32
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     dark + fire + flying + ghost + grass + ground + ice + normal + 
##     poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - grass          1     116.2 157785 2990.5
## - poison         1     150.0 157819 2990.6
## - fire           1     243.7 157912 2990.9
## - dark           1     334.9 158004 2991.2
## - legendary      1     489.0 158158 2991.7
## - flying:normal  1     610.0 158279 2992.0
## - defense        1     678.1 158347 2992.2
## - rock           1    1274.9 158944 2994.1
## - ground         1    1407.0 159076 2994.5
## - ice            1    1409.7 159078 2994.6
## - ghost          1    1920.3 159589 2996.2
## <none>                       157669 2996.3
## - water          1    2052.5 159721 2996.6
## - speed          1    2335.7 160004 2997.4
## - steel          1    3147.0 160816 3000.0
## - spattack       1    4131.0 161800 3003.0
## - spdefense      1    7821.2 165490 3014.3
## - attack         1   24359.0 182028 3061.8
## 
## Step:  AIC=2990.47
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     dark + fire + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - poison         1     152.2 157937 2984.7
## - fire           1     199.8 157985 2984.9
## - dark           1     303.0 158088 2985.2
## - legendary      1     501.9 158287 2985.8
## - flying:normal  1     623.5 158408 2986.2
## - defense        1     661.9 158447 2986.3
## - rock           1    1207.2 158992 2988.1
## - ice            1    1489.8 159275 2988.9
## - ground         1    1535.1 159320 2989.1
## - ghost          1    1880.7 159666 2990.2
## <none>                       157785 2990.5
## - speed          1    2247.9 160033 2991.3
## - water          1    2333.8 160119 2991.6
## - steel          1    3034.3 160819 2993.8
## - spattack       1    4059.2 161844 2996.9
## - spdefense      1    7848.4 165633 3008.5
## - attack         1   24401.7 182186 3056.0
## 
## Step:  AIC=2984.74
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     dark + fire + flying + ghost + ground + ice + normal + rock + 
##     steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - fire           1     246.5 158183 2979.3
## - dark           1     351.6 158289 2979.6
## - legendary      1     471.6 158409 2980.0
## - flying:normal  1     607.0 158544 2980.4
## - defense        1     653.2 158590 2980.6
## - rock           1    1306.3 159243 2982.6
## - ice            1    1400.1 159337 2982.9
## - ground         1    1455.7 159393 2983.1
## - ghost          1    1880.5 159818 2984.4
## <none>                       157937 2984.7
## - water          1    2212.0 160149 2985.5
## - speed          1    2257.2 160194 2985.6
## - steel          1    3234.9 161172 2988.7
## - spattack       1    4024.6 161962 2991.1
## - spdefense      1    7839.6 165777 3002.7
## - attack         1   24394.6 182332 3050.2
## 
## Step:  AIC=2979.31
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     dark + flying + ghost + ground + ice + normal + rock + steel + 
##     water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - dark           1     339.9 158523 2974.2
## - legendary      1     473.4 158657 2974.6
## - flying:normal  1     598.3 158782 2975.0
## - defense        1     649.2 158833 2975.1
## - rock           1    1284.5 159468 2977.1
## - ground         1    1472.0 159656 2977.7
## - ice            1    1525.8 159709 2977.9
## - ghost          1    1856.0 160040 2978.9
## <none>                       158183 2979.3
## - speed          1    2260.4 160444 2980.2
## - water          1    2470.4 160654 2980.8
## - steel          1    3145.3 161329 2982.9
## - spattack       1    3788.7 161972 2984.9
## - spdefense      1    8024.6 166208 2997.8
## - attack         1   24443.3 182627 3044.8
## 
## Step:  AIC=2974.17
## hp ~ attack + defense + spattack + spdefense + speed + legendary + 
##     flying + ghost + ground + ice + normal + rock + steel + water + 
##     flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - legendary      1     528.7 159052 2969.6
## - flying:normal  1     607.6 159131 2969.9
## - defense        1     707.0 159230 2970.2
## - rock           1    1216.9 159740 2971.8
## - ground         1    1536.2 160060 2972.8
## - ice            1    1582.5 160106 2972.9
## - ghost          1    1916.8 160440 2973.9
## <none>                       158523 2974.2
## - speed          1    2319.5 160843 2975.2
## - water          1    2556.0 161079 2975.9
## - steel          1    3039.4 161563 2977.4
## - spattack       1    3865.2 162389 2980.0
## - spdefense      1    8020.9 166544 2992.6
## - attack         1   24282.5 182806 3039.1
## 
## Step:  AIC=2969.62
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - flying:normal  1     687.0 159739 2965.6
## - defense        1     788.5 159841 2965.9
## - rock           1    1245.1 160297 2967.3
## - ice            1    1561.1 160613 2968.3
## - ground         1    1621.3 160673 2968.5
## - ghost          1    1934.6 160987 2969.4
## <none>                       159052 2969.6
## - speed          1    2203.3 161255 2970.3
## - water          1    2413.0 161465 2970.9
## - steel          1    3229.3 162281 2973.4
## - spattack       1    4711.3 163763 2978.0
## - spdefense      1    8620.8 167673 2989.7
## - attack         1   25813.1 184865 3038.4
## 
## Step:  AIC=2965.55
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + rock + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - defense    1     780.1 160519 2961.8
## - rock       1    1270.7 161010 2963.3
## - flying     1    1378.1 161117 2963.6
## - ice        1    1509.4 161248 2964.0
## - ground     1    1601.0 161340 2964.3
## <none>                   159739 2965.6
## - ghost      1    2001.3 161740 2965.6
## - speed      1    2172.9 161912 2966.1
## - water      1    2329.8 162069 2966.6
## - steel      1    3341.9 163081 2969.7
## - spattack   1    4605.5 164345 2973.5
## - normal     1    6212.1 165951 2978.4
## - spdefense  1    9049.1 168788 2986.8
## - attack     1   25824.6 185564 3034.1
## 
## Step:  AIC=2961.77
## hp ~ attack + spattack + spdefense + speed + flying + ghost + 
##     ground + ice + normal + rock + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - rock       1       806 161325 2958.1
## - flying     1      1405 161924 2959.9
## - ice        1      1527 162046 2960.3
## - ghost      1      1817 162336 2961.2
## - ground     1      1835 162354 2961.2
## <none>                   160519 2961.8
## - speed      1      2544 163063 2963.4
## - steel      1      2637 163156 2963.7
## - water      1      2764 163283 2964.1
## - spattack   1      4525 165044 2969.4
## - normal     1      6106 166626 2974.2
## - spdefense  1     14816 175335 2999.6
## - attack     1     35013 195533 3054.0
## 
## Step:  AIC=2958.06
## hp ~ attack + spattack + spdefense + speed + flying + ghost + 
##     ground + ice + normal + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - flying     1      1387 162712 2956.1
## - ghost      1      1636 162961 2956.9
## - ice        1      1644 162969 2956.9
## - ground     1      1796 163121 2957.4
## <none>                   161325 2958.1
## - speed      1      2170 163495 2958.5
## - water      1      2610 163935 2959.8
## - steel      1      2847 164172 2960.6
## - spattack   1      5028 166353 2967.2
## - normal     1      6592 167916 2971.8
## - spdefense  1     14517 175842 2994.8
## - attack     1     34211 195535 3047.8
## 
## Step:  AIC=2956.12
## hp ~ attack + spattack + spdefense + speed + ghost + ground + 
##     ice + normal + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - ice        1      1500 164212 2954.5
## - speed      1      1562 164274 2954.7
## - ground     1      1677 164389 2955.0
## - ghost      1      1784 164496 2955.3
## <none>                   162712 2956.1
## - water      1      2323 165036 2957.0
## - steel      1      3053 165765 2959.2
## - spattack   1      4964 167676 2964.9
## - normal     1      6764 169476 2970.2
## - spdefense  1     14391 177103 2992.2
## - attack     1     33713 196426 3043.9
## 
## Step:  AIC=2954.48
## hp ~ attack + spattack + spdefense + speed + ghost + ground + 
##     normal + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - speed      1      1618 165831 2953.2
## - ground     1      1673 165885 2953.3
## - ghost      1      1851 166063 2953.9
## <none>                   164212 2954.5
## - water      1      2242 166454 2955.0
## - steel      1      3427 167639 2958.6
## - spattack   1      5046 169258 2963.4
## - normal     1      6263 170475 2966.9
## - spdefense  1     14593 178805 2990.8
## - attack     1     34373 198586 3043.1
## 
## Step:  AIC=2953.17
## hp ~ attack + spattack + spdefense + ghost + ground + normal + 
##     steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - ghost      1      1555 167386 2951.6
## - ground     1      1921 167752 2952.7
## <none>                   165831 2953.2
## - water      1      2485 168315 2954.4
## - steel      1      2803 168634 2955.3
## - spattack   1      3735 169566 2958.1
## - normal     1      5510 171341 2963.3
## - spdefense  1     14037 179868 2987.5
## - attack     1     32757 198588 3036.9
## 
## Step:  AIC=2951.61
## hp ~ attack + spattack + spdefense + ground + normal + steel + 
##     water
## 
##             Df Sum of Sq    RSS    AIC
## <none>                   167386 2951.6
## - ground     1      2134 169520 2951.7
## - water      1      2987 170373 2954.2
## - steel      1      3152 170538 2954.7
## - spattack   1      3554 170940 2955.9
## - normal     1      6080 173466 2963.2
## - spdefense  1     13948 181334 2985.3
## - attack     1     33522 200908 3036.5
summary(mbic)
## 
## Call:
## lm(formula = hp ~ attack + spattack + spdefense + ground + normal + 
##     steel + water, data = data[-which(t == 231), ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -46.271 -10.977  -2.112   8.264 144.950 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  18.35734    2.92848   6.269 7.99e-10 ***
## attack        0.28805    0.02905   9.916  < 2e-16 ***
## spattack      0.10706    0.03316   3.229  0.00133 ** 
## spdefense     0.23542    0.03680   6.396 3.71e-10 ***
## groundTRUE    7.72983    3.08949   2.502  0.01267 *  
## normalTRUE   11.50007    2.72321   4.223 2.87e-05 ***
## steelTRUE   -10.69788    3.51821  -3.041  0.00249 ** 
## waterTRUE     6.65625    2.24886   2.960  0.00323 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 18.46 on 491 degrees of freedom
## Multiple R-squared:  0.4064, Adjusted R-squared:  0.398 
## F-statistic: 48.03 on 7 and 491 DF,  p-value: < 2.2e-16
outlierTest(mbic)
##     rstudent unadjusted p-value Bonferonni p
## 218 8.431894         3.8291e-16   1.9107e-13
## 352 5.558996         4.4638e-08   2.2274e-05
plot(mbic)

influencePlot(mbic)

##        StudRes         Hat        CookD
## 751 -1.0471733 0.064736284 0.0094858316
## 352  5.5589963 0.016334337 0.0604619144
## 752 -0.1524967 0.063402813 0.0001971749
## 218  8.4318944 0.009387304 0.0736955055
ncvTest(mbic)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 0.06875731, Df = 1, p = 0.79315
vif(mbic)
##    attack  spattack spdefense    ground    normal     steel     water 
##  1.257610  1.599520  1.454313  1.076962  1.081476  1.055632  1.046175
mfinal = lm(hp ~ attack + spattack + spdefense + ground + normal + steel + water, data = test)
summary(mfinal)
## 
## Call:
## lm(formula = hp ~ attack + spattack + spdefense + ground + normal + 
##     steel + water, data = test)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -51.731 -12.355  -3.645   6.510 169.453 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 24.68413    5.13633   4.806 2.47e-06 ***
## attack       0.16280    0.04880   3.336  0.00096 ***
## spattack     0.11692    0.05361   2.181  0.02999 *  
## spdefense    0.29357    0.06153   4.771 2.89e-06 ***
## groundTRUE   9.57931    5.33305   1.796  0.07349 .  
## normalTRUE  20.13220    4.16540   4.833 2.17e-06 ***
## steelTRUE   -3.96829    6.18219  -0.642  0.52145    
## waterTRUE    2.32774    4.25522   0.547  0.58477    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 24.59 on 292 degrees of freedom
## Multiple R-squared:  0.2492, Adjusted R-squared:  0.2312 
## F-statistic: 13.85 on 7 and 292 DF,  p-value: 1.738e-15
outlierTest(mfinal)
##     rstudent unadjusted p-value Bonferonni p
## 122 7.761370         1.4350e-13   4.3050e-11
## 262 7.326360         2.3386e-12   7.0157e-10
## 656 4.609078         6.0605e-06   1.8182e-03
plot(mfinal)

influencePlot(mfinal)

##        StudRes        Hat      CookD
## 416 -0.9950667 0.09868741 0.01355237
## 430 -1.3350373 0.11142279 0.02786209
## 122  7.7613696 0.05171101 0.34135744
## 262  7.3263596 0.06710540 0.40886860
mfull3 = lm(hp ~ attack + defense + spattack + spdefense + speed + generation + legendary + bug + dark + dragon + electric + fairy + fighting + fire + flying + ghost + grass + ground + ice + normal + poison + psychic + rock + steel + water + normal*flying + bug*flying, data = data[data$dex != 213 & data$hp <= mean(data$hp)+sd(data$hp)*2.5,])
summary(mfull3)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + speed + 
##     generation + legendary + bug + dark + dragon + electric + 
##     fairy + fighting + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + psychic + rock + steel + water + 
##     normal * flying + bug * flying, data = data[data$dex != 213 & 
##     data$hp <= mean(data$hp) + sd(data$hp) * 2.5, ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -46.963  -9.171  -1.697   8.422  60.607 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            12.78731    3.68505   3.470 0.000569 ***
## attack                  0.25799    0.03044   8.476 3.20e-16 ***
## defense                 0.09562    0.03432   2.786 0.005562 ** 
## spattack                0.14923    0.03300   4.522 7.80e-06 ***
## spdefense               0.18192    0.03496   5.203 2.95e-07 ***
## speed                  -0.05782    0.03121  -1.853 0.064586 .  
## generation2             7.49312    2.44197   3.068 0.002279 ** 
## generation3             2.40005    2.18889   1.096 0.273447    
## generation4             8.15462    2.42684   3.360 0.000844 ***
## generation5             8.57697    2.19053   3.915 0.000104 ***
## generation6             7.66835    2.77589   2.762 0.005967 ** 
## legendaryTrue           1.42109    2.95380   0.481 0.630670    
## bugTRUE                -0.16689    3.08695  -0.054 0.956907    
## darkTRUE               -3.03808    2.84375  -1.068 0.285930    
## dragonTRUE             -0.72945    3.18401  -0.229 0.818896    
## electricTRUE           -1.39601    3.43036  -0.407 0.684230    
## fairyTRUE               1.08070    3.49637   0.309 0.757392    
## fightingTRUE            1.27905    3.07253   0.416 0.677396    
## fireTRUE               -3.36886    3.21086  -1.049 0.294635    
## flyingTRUE              7.49769    2.58585   2.900 0.003917 ** 
## ghostTRUE             -12.45051    3.59144  -3.467 0.000576 ***
## grassTRUE              -1.14230    2.59394  -0.440 0.659874    
## groundTRUE              8.52792    2.72143   3.134 0.001837 ** 
## iceTRUE                 5.92305    3.26748   1.813 0.070526 .  
## normalTRUE             11.36375    3.10225   3.663 0.000278 ***
## poisonTRUE              5.73867    2.85734   2.008 0.045187 *  
## psychicTRUE            -2.09688    2.98480  -0.703 0.482712    
## rockTRUE               -5.45689    2.89390  -1.886 0.059973 .  
## steelTRUE             -12.17275    3.28952  -3.700 0.000241 ***
## waterTRUE               3.70532    2.41138   1.537 0.125080    
## flyingTRUE:normalTRUE  -7.25462    5.46106  -1.328 0.184697    
## bugTRUE:flyingTRUE     -4.87279    6.04304  -0.806 0.420460    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 14.78 on 459 degrees of freedom
## Multiple R-squared:  0.558,  Adjusted R-squared:  0.5282 
## F-statistic: 18.69 on 31 and 459 DF,  p-value: < 2.2e-16
outlierTest(mfull3)
##     rstudent unadjusted p-value Bonferonni p
## 186 4.323786         1.8834e-05    0.0092475
plot(mfull3)

influencePlot(mfull3)

##        StudRes        Hat       CookD
## 751 -0.5361895 0.14694464 0.001550022
## 796 -3.4375772 0.12527684 0.051670077
## 138 -1.5902203 0.14372799 0.013220568
## 489  3.8057344 0.06517372 0.030654518
## 186  4.3237859 0.06569400 0.039553686
mbic2 = stepAIC(mfull3, k = log(length(mfull3$residuals)))
## Start:  AIC=2809.89
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + dragon + electric + fairy + fighting + 
##     fire + flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + normal * flying + bug * 
##     flying
## 
##                 Df Sum of Sq    RSS    AIC
## - dragon         1      11.5 100258 2803.8
## - fairy          1      20.9 100267 2803.8
## - electric       1      36.2 100282 2803.9
## - fighting       1      37.8 100284 2803.9
## - grass          1      42.4 100289 2803.9
## - legendary      1      50.6 100297 2803.9
## - psychic        1     107.8 100354 2804.2
## - bug:flying     1     142.0 100388 2804.4
## - generation     5    5366.1 105612 2804.5
## - fire           1     240.4 100487 2804.9
## - dark           1     249.3 100496 2804.9
## - flying:normal  1     385.4 100632 2805.6
## - water          1     515.7 100762 2806.2
## - ice            1     717.7 100964 2807.2
## - speed          1     749.6 100996 2807.3
## - rock           1     776.6 101023 2807.5
## - poison         1     881.0 101127 2808.0
## <none>                       100246 2809.9
## - defense        1    1694.9 101941 2811.9
## - ground         1    2144.6 102391 2814.1
## - ghost          1    2624.8 102871 2816.4
## - steel          1    2990.7 103237 2818.1
## - spattack       1    4466.3 104713 2825.1
## - spdefense      1    5913.4 106160 2831.8
## - attack         1   15690.5 115937 2875.1
## 
## Step:  AIC=2803.75
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fairy + fighting + fire + 
##     flying + ghost + grass + ground + ice + normal + poison + 
##     psychic + rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fairy          1      27.5 100285 2797.7
## - electric       1      28.8 100287 2797.7
## - grass          1      32.8 100291 2797.7
## - legendary      1      50.1 100308 2797.8
## - fighting       1      53.8 100312 2797.8
## - psychic        1      96.4 100354 2798.0
## - bug:flying     1     137.7 100396 2798.2
## - generation     5    5354.9 105613 2798.3
## - fire           1     230.1 100488 2798.7
## - dark           1     237.9 100496 2798.7
## - flying:normal  1     387.1 100645 2799.4
## - water          1     638.3 100896 2800.7
## - speed          1     749.8 101008 2801.2
## - rock           1     772.2 101030 2801.3
## - ice            1     793.7 101051 2801.4
## - poison         1     963.8 101222 2802.2
## <none>                       100258 2803.8
## - defense        1    1686.5 101944 2805.7
## - ground         1    2247.8 102506 2808.4
## - ghost          1    2685.1 102943 2810.5
## - steel          1    3026.8 103285 2812.2
## - spattack       1    4477.8 104736 2819.0
## - spdefense      1    5902.9 106161 2825.6
## - attack         1   15712.6 115970 2869.0
## 
## Step:  AIC=2797.68
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fighting + fire + flying + 
##     ghost + grass + ground + ice + normal + poison + psychic + 
##     rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - fighting       1      43.5 100329 2791.7
## - electric       1      45.4 100331 2791.7
## - legendary      1      47.8 100333 2791.7
## - grass          1      48.1 100333 2791.7
## - psychic        1     122.5 100408 2792.1
## - bug:flying     1     140.0 100425 2792.2
## - generation     5    5370.9 105656 2792.3
## - dark           1     270.1 100555 2792.8
## - fire           1     278.0 100563 2792.8
## - flying:normal  1     382.2 100668 2793.4
## - water          1     611.3 100897 2794.5
## - ice            1     766.1 101051 2795.2
## - speed          1     771.1 101056 2795.2
## - rock           1     825.0 101110 2795.5
## - poison         1     936.4 101222 2796.1
## <none>                       100285 2797.7
## - defense        1    1678.3 101964 2799.6
## - ground         1    2223.5 102509 2802.3
## - ghost          1    2884.7 103170 2805.4
## - steel          1    3045.1 103330 2806.2
## - spattack       1    4553.3 104839 2813.3
## - spdefense      1    6093.3 106379 2820.4
## - attack         1   15832.5 116118 2863.5
## 
## Step:  AIC=2791.7
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     legendary + bug + dark + electric + fire + flying + ghost + 
##     grass + ground + ice + normal + poison + psychic + rock + 
##     steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - legendary      1      42.9 100372 2785.7
## - electric       1      62.3 100391 2785.8
## - grass          1      65.4 100394 2785.8
## - bug:flying     1     131.9 100461 2786.2
## - psychic        1     139.8 100469 2786.2
## - generation     5    5428.4 105757 2786.6
## - fire           1     297.5 100626 2787.0
## - dark           1     323.6 100652 2787.1
## - flying:normal  1     368.1 100697 2787.3
## - water          1     570.9 100900 2788.3
## - ice            1     724.5 101053 2789.0
## - speed          1     752.1 101081 2789.2
## - poison         1     900.4 101229 2789.9
## - rock           1     904.5 101233 2789.9
## <none>                       100329 2791.7
## - defense        1    1659.4 101988 2793.6
## - ground         1    2200.5 102529 2796.2
## - ghost          1    3022.4 103351 2800.1
## - steel          1    3178.7 103508 2800.8
## - spattack       1    4529.4 104858 2807.2
## - spdefense      1    6147.3 106476 2814.7
## - attack         1   16901.8 117231 2861.9
## 
## Step:  AIC=2785.71
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     bug + dark + electric + fire + flying + ghost + grass + ground + 
##     ice + normal + poison + psychic + rock + steel + water + 
##     flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - electric       1      63.5 100435 2779.8
## - grass          1      69.2 100441 2779.9
## - psychic        1     136.4 100508 2780.2
## - bug:flying     1     152.1 100524 2780.3
## - fire           1     302.3 100674 2781.0
## - generation     5    5546.9 105919 2781.1
## - dark           1     345.4 100717 2781.2
## - flying:normal  1     392.2 100764 2781.4
## - water          1     553.1 100925 2782.2
## - ice            1     715.7 101087 2783.0
## - speed          1     737.2 101109 2783.1
## - poison         1     888.6 101260 2783.8
## - rock           1     919.1 101291 2784.0
## <none>                       100372 2785.7
## - defense        1    1695.9 102068 2787.7
## - ground         1    2219.2 102591 2790.3
## - ghost          1    3060.0 103432 2794.3
## - steel          1    3271.9 103644 2795.3
## - spattack       1    4908.9 105281 2803.0
## - spdefense      1    6296.6 106668 2809.4
## - attack         1   17564.6 117936 2858.7
## 
## Step:  AIC=2779.83
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     bug + dark + fire + flying + ghost + grass + ground + ice + 
##     normal + poison + psychic + rock + steel + water + flying:normal + 
##     bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - grass          1      44.2 100479 2773.8
## - psychic        1      91.4 100527 2774.1
## - bug:flying     1     138.0 100573 2774.3
## - fire           1     252.8 100688 2774.9
## - dark           1     307.7 100743 2775.1
## - generation     5    5528.4 105964 2775.2
## - flying:normal  1     395.9 100831 2775.6
## - water          1     722.2 101157 2777.2
## - speed          1     772.4 101208 2777.4
## - ice            1     831.2 101266 2777.7
## - rock           1     875.7 101311 2777.9
## - poison         1    1034.9 101470 2778.7
## <none>                       100435 2779.8
## - defense        1    1687.1 102122 2781.8
## - ground         1    2300.7 102736 2784.8
## - ghost          1    2996.6 103432 2788.1
## - steel          1    3243.9 103679 2789.2
## - spattack       1    4959.7 105395 2797.3
## - spdefense      1    6331.2 106766 2803.7
## - attack         1   18824.6 119260 2858.0
## 
## Step:  AIC=2773.85
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     bug + dark + fire + flying + ghost + ground + ice + normal + 
##     poison + psychic + rock + steel + water + flying:normal + 
##     bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - psychic        1      65.7 100545 2768.0
## - bug:flying     1     131.2 100611 2768.3
## - fire           1     220.0 100699 2768.7
## - generation     5    5497.5 105977 2769.0
## - dark           1     283.0 100762 2769.0
## - flying:normal  1     402.3 100882 2769.6
## - speed          1     744.5 101224 2771.3
## - rock           1     838.8 101318 2771.7
## - water          1     868.0 101347 2771.9
## - ice            1     899.3 101379 2772.0
## - poison         1    1046.9 101526 2772.7
## <none>                       100479 2773.8
## - defense        1    1668.8 102148 2775.7
## - ground         1    2458.3 102938 2779.5
## - ghost          1    2954.6 103434 2781.9
## - steel          1    3214.7 103694 2783.1
## - spattack       1    4915.8 105395 2791.1
## - spdefense      1    6326.8 106806 2797.6
## - attack         1   19116.5 119596 2853.2
## 
## Step:  AIC=2767.97
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     bug + dark + fire + flying + ghost + ground + ice + normal + 
##     poison + rock + steel + water + flying:normal + bug:flying
## 
##                 Df Sum of Sq    RSS    AIC
## - bug:flying     1     125.7 100671 2762.4
## - fire           1     181.8 100727 2762.7
## - dark           1     265.7 100811 2763.1
## - flying:normal  1     408.3 100954 2763.8
## - generation     5    5650.8 106196 2763.8
## - speed          1     785.3 101331 2765.6
## - rock           1     816.7 101362 2765.8
## - ice            1     977.1 101522 2766.5
## - water          1    1029.2 101574 2766.8
## - poison         1    1177.2 101722 2767.5
## <none>                       100545 2768.0
## - defense        1    1661.6 102207 2769.8
## - ground         1    2485.0 103030 2773.8
## - ghost          1    2892.1 103437 2775.7
## - steel          1    3186.7 103732 2777.1
## - spattack       1    4898.8 105444 2785.1
## - spdefense      1    6261.3 106806 2791.4
## - attack         1   21057.6 121603 2855.1
## 
## Step:  AIC=2762.39
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     bug + dark + fire + flying + ghost + ground + ice + normal + 
##     poison + rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - bug            1      41.8 100713 2756.4
## - fire           1     169.6 100840 2757.0
## - dark           1     267.4 100938 2757.5
## - flying:normal  1     345.3 101016 2757.9
## - generation     5    5665.6 106337 2758.3
## - speed          1     746.8 101418 2759.8
## - rock           1     807.8 101479 2760.1
## - ice            1     980.0 101651 2760.9
## - water          1    1024.2 101695 2761.2
## - poison         1    1273.2 101944 2762.4
## <none>                       100671 2762.4
## - defense        1    1683.7 102355 2764.3
## - ground         1    2477.3 103148 2768.1
## - ghost          1    2917.5 103588 2770.2
## - steel          1    3121.1 103792 2771.2
## - spattack       1    4794.1 105465 2779.0
## - spdefense      1    6255.6 106927 2785.8
## - attack         1   21128.9 121800 2849.7
## 
## Step:  AIC=2756.4
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     dark + fire + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - fire           1     156.5 100869 2751.0
## - dark           1     247.4 100960 2751.4
## - flying:normal  1     335.8 101049 2751.8
## - generation     5    5633.2 106346 2752.1
## - speed          1     754.0 101467 2753.9
## - rock           1     788.8 101502 2754.0
## - ice            1    1025.8 101738 2755.2
## - water          1    1125.2 101838 2755.7
## - poison         1    1245.7 101958 2756.2
## <none>                       100713 2756.4
## - defense        1    1664.7 102377 2758.2
## - ground         1    2584.4 103297 2762.6
## - ghost          1    2877.3 103590 2764.0
## - steel          1    3143.6 103856 2765.3
## - spattack       1    4971.8 105685 2773.9
## - spdefense      1    6366.2 107079 2780.3
## - attack         1   21109.6 121822 2843.6
## 
## Step:  AIC=2750.96
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     dark + flying + ghost + ground + ice + normal + poison + 
##     rock + steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - dark           1     234.5 101104 2745.9
## - generation     5    5548.5 106418 2746.3
## - flying:normal  1     337.4 101207 2746.4
## - speed          1     761.5 101631 2748.5
## - rock           1     765.3 101635 2748.5
## - ice            1    1132.3 102001 2750.2
## - water          1    1280.2 102149 2751.0
## <none>                       100869 2751.0
## - poison         1    1358.2 102227 2751.3
## - defense        1    1655.2 102524 2752.8
## - ground         1    2611.2 103480 2757.3
## - ghost          1    2860.1 103729 2758.5
## - steel          1    3057.4 103927 2759.4
## - spattack       1    4818.4 105688 2767.7
## - spdefense      1    6558.9 107428 2775.7
## - attack         1   21097.5 121967 2838.0
## 
## Step:  AIC=2745.91
## hp ~ attack + defense + spattack + spdefense + speed + generation + 
##     flying + ghost + ground + ice + normal + poison + rock + 
##     steel + water + flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - generation     5    5395.9 106500 2740.4
## - flying:normal  1     351.0 101455 2741.4
## - rock           1     718.4 101822 2743.2
## - speed          1     797.5 101901 2743.6
## - ice            1    1189.5 102293 2745.4
## <none>                       101104 2745.9
## - water          1    1319.6 102423 2746.1
## - poison         1    1423.8 102528 2746.6
## - defense        1    1725.5 102829 2748.0
## - ground         1    2713.8 103817 2752.7
## - ghost          1    2941.4 104045 2753.8
## - steel          1    2955.9 104060 2753.9
## - spattack       1    4937.8 106041 2763.1
## - spdefense      1    6591.5 107695 2770.7
## - attack         1   21004.1 122108 2832.4
## 
## Step:  AIC=2740.45
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + poison + rock + steel + water + 
##     flying:normal
## 
##                 Df Sum of Sq    RSS    AIC
## - flying:normal  1     526.1 107026 2736.7
## - poison         1     533.0 107033 2736.7
## - rock           1     730.0 107230 2737.6
## - water          1     776.8 107276 2737.8
## - speed          1     956.6 107456 2738.7
## <none>                       106500 2740.4
## - defense        1    1471.9 107971 2741.0
## - ice            1    1538.7 108038 2741.3
## - ground         1    2435.5 108935 2745.4
## - steel          1    2568.9 109069 2746.0
## - ghost          1    2948.3 109448 2747.7
## - spattack       1    4818.3 111318 2756.0
## - spdefense      1    7356.4 113856 2767.1
## - attack         1   22228.1 128728 2827.3
## 
## Step:  AIC=2736.68
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + poison + rock + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - poison     1     500.1 107526 2732.8
## - water      1     732.4 107758 2733.8
## - rock       1     749.7 107775 2733.9
## - speed      1     928.2 107954 2734.7
## <none>                   107026 2736.7
## - defense    1    1467.7 108493 2737.2
## - ice        1    1491.0 108517 2737.3
## - flying     1    2002.5 109028 2739.6
## - ground     1    2411.4 109437 2741.4
## - steel      1    2663.2 109689 2742.6
## - ghost      1    3013.0 110039 2744.1
## - spattack   1    4718.1 111744 2751.7
## - normal     1    5017.0 112043 2753.0
## - spdefense  1    7693.9 114720 2764.6
## - attack     1   22151.9 129178 2822.8
## 
## Step:  AIC=2732.77
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + rock + steel + water
## 
##             Df Sum of Sq    RSS    AIC
## - water      1     608.5 108134 2729.3
## - rock       1     870.9 108397 2730.5
## - speed      1     950.1 108476 2730.9
## - ice        1    1335.7 108861 2732.6
## <none>                   107526 2732.8
## - defense    1    1446.5 108972 2733.1
## - flying     1    1878.1 109404 2735.1
## - ground     1    2228.8 109755 2736.7
## - steel      1    2923.4 110449 2739.7
## - ghost      1    3004.9 110531 2740.1
## - spattack   1    4561.5 112087 2747.0
## - normal     1    4632.6 112158 2747.3
## - spdefense  1    7676.9 115203 2760.4
## - attack     1   21977.8 129504 2817.9
## 
## Step:  AIC=2729.34
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + rock + steel
## 
##             Df Sum of Sq    RSS    AIC
## - rock       1     856.8 108991 2727.0
## - speed      1     955.2 109090 2727.5
## - ice        1    1267.6 109402 2728.9
## <none>                   108134 2729.3
## - flying     1    1721.9 109856 2730.9
## - defense    1    1784.9 109919 2731.2
## - ground     1    2097.0 110231 2732.6
## - ghost      1    3386.9 111521 2738.3
## - steel      1    3425.7 111560 2738.5
## - normal     1    4236.7 112371 2742.0
## - spattack   1    4813.3 112948 2744.5
## - spdefense  1    7305.1 115439 2755.2
## - attack     1   21502.7 129637 2812.2
## 
## Step:  AIC=2727.02
## hp ~ attack + defense + spattack + spdefense + speed + flying + 
##     ghost + ground + ice + normal + steel
## 
##             Df Sum of Sq    RSS    AIC
## - speed      1     779.2 109770 2724.3
## - defense    1    1213.8 110205 2726.3
## - ice        1    1374.1 110365 2727.0
## <none>                   108991 2727.0
## - flying     1    1716.7 110708 2728.5
## - ground     1    2139.6 111131 2730.4
## - ghost      1    3084.0 112075 2734.5
## - steel      1    3265.1 112256 2735.3
## - normal     1    4583.3 113574 2741.1
## - spattack   1    5280.4 114272 2744.1
## - spdefense  1    7913.6 116905 2755.2
## - attack     1   21360.9 130352 2808.7
## 
## Step:  AIC=2724.32
## hp ~ attack + defense + spattack + spdefense + flying + ghost + 
##     ground + ice + normal + steel
## 
##             Df Sum of Sq    RSS    AIC
## - flying     1    1319.8 111090 2724.0
## - ice        1    1382.7 111153 2724.3
## <none>                   109770 2724.3
## - defense    1    1658.6 111429 2725.5
## - ground     1    2261.0 112031 2728.1
## - ghost      1    2863.4 112634 2730.8
## - steel      1    3063.7 112834 2731.6
## - normal     1    4164.3 113935 2736.4
## - spattack   1    4533.8 114304 2738.0
## - spdefense  1    7360.6 117131 2750.0
## - attack     1   20776.9 130547 2803.2
## 
## Step:  AIC=2724
## hp ~ attack + defense + spattack + spdefense + ghost + ground + 
##     ice + normal + steel
## 
##             Df Sum of Sq    RSS    AIC
## - ice        1    1255.2 112345 2723.3
## <none>                   111090 2724.0
## - defense    1    1549.7 112640 2724.6
## - ground     1    2105.0 113195 2727.0
## - ghost      1    3076.1 114166 2731.2
## - steel      1    3307.8 114398 2732.2
## - normal     1    4549.9 115640 2737.5
## - spattack   1    4813.5 115904 2738.6
## - spdefense  1    7485.7 118576 2749.8
## - attack     1   21104.1 132194 2803.2
## 
## Step:  AIC=2723.32
## hp ~ attack + defense + spattack + spdefense + ghost + ground + 
##     normal + steel
## 
##             Df Sum of Sq    RSS    AIC
## <none>                   112345 2723.3
## - defense    1    1526.2 113872 2723.8
## - ground     1    2116.3 114462 2726.3
## - ghost      1    3121.2 115466 2730.6
## - steel      1    3606.4 115952 2732.6
## - normal     1    4177.0 116522 2735.0
## - spattack   1    4862.3 117208 2737.9
## - spdefense  1    7586.9 119932 2749.2
## - attack     1   21553.5 133899 2803.3
summary(mbic2)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + ghost + 
##     ground + normal + steel, data = data[data$dex != 213 & data$hp <= 
##     mean(data$hp) + sd(data$hp) * 2.5, ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -46.814  -9.655  -1.544   8.564  63.819 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  17.34339    2.49922   6.940 1.27e-11 ***
## attack        0.25289    0.02630   9.616  < 2e-16 ***
## defense       0.08269    0.03231   2.559 0.010804 *  
## spattack      0.12656    0.02771   4.567 6.28e-06 ***
## spdefense     0.19415    0.03403   5.705 2.03e-08 ***
## ghostTRUE   -12.07666    3.30021  -3.659 0.000281 ***
## groundTRUE    7.74515    2.57034   3.013 0.002720 ** 
## normalTRUE    9.61770    2.27191   4.233 2.76e-05 ***
## steelTRUE   -12.23566    3.11062  -3.934 9.60e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 15.27 on 482 degrees of freedom
## Multiple R-squared:  0.5047, Adjusted R-squared:  0.4964 
## F-statistic: 61.39 on 8 and 482 DF,  p-value: < 2.2e-16
outlierTest(mbic2)
##     rstudent unadjusted p-value Bonferonni p
## 186 4.263101         2.4274e-05     0.011918
plot(mbic2)

influencePlot(mbic2)

##        StudRes         Hat       CookD
## 751 -0.2643268 0.119429091 0.001054932
## 489  3.8515213 0.038678628 0.064466652
## 752  0.4462974 0.099566112 0.002451253
## 186  4.2631006 0.004254635 0.008331394
## 473  3.6142046 0.049254624 0.073355201
ncvTest(mbic2)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 1.110854, Df = 1, p = 0.2919
vif(mbic2)
##    attack   defense  spattack spdefense     ghost    ground    normal 
##  1.479233  1.888897  1.615273  1.789073  1.024396  1.088649  1.064312 
##     steel 
##  1.205654
mfinal2 = lm(hp ~ attack + defense + spattack + spdefense + ghost + ground + normal + steel, data = test[test$hp <= mean(data$hp)+sd(data$hp)*2.5,])
summary(mfinal2)
## 
## Call:
## lm(formula = hp ~ attack + defense + spattack + spdefense + ghost + 
##     ground + normal + steel, data = test[test$hp <= mean(data$hp) + 
##     sd(data$hp) * 2.5, ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -53.615  -9.256  -2.061   6.390  59.358 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 25.74911    3.46339   7.435 1.25e-12 ***
## attack       0.19425    0.03549   5.474 9.72e-08 ***
## defense      0.07101    0.04099   1.732  0.08431 .  
## spattack     0.14975    0.03707   4.040 6.88e-05 ***
## spdefense    0.13650    0.04916   2.777  0.00586 ** 
## ghostTRUE   -7.62474    3.87030  -1.970  0.04981 *  
## groundTRUE   7.97582    3.68522   2.164  0.03128 *  
## normalTRUE   9.58041    2.89738   3.307  0.00107 ** 
## steelTRUE   -4.99902    4.34311  -1.151  0.25069    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.46 on 283 degrees of freedom
## Multiple R-squared:  0.3988, Adjusted R-squared:  0.3818 
## F-statistic: 23.46 on 8 and 283 DF,  p-value: < 2.2e-16
outlierTest(mfinal2)
## No Studentized residuals with Bonferonni p < 0.05
## Largest |rstudent|:
##    rstudent unadjusted p-value Bonferonni p
## 45 3.752167         0.00021282     0.062144
plot(mfinal2)

influencePlot(mfinal2)

##        StudRes        Hat      CookD
## 430 -2.7482358 0.12536276 0.11756139
## 45   3.7521668 0.03338286 0.05163806
## 797 -3.3781552 0.03584554 0.04546884
## 590  2.2619737 0.13221175 0.08537233
## 334 -0.9251977 0.13296255 0.01459282